#!/bin/bash

# install fabric docker image
echo -e "\e[1;32m正在安装Fabric镜像 \e[0m"
docker load --input ./images/hyperledger-fabric-tools-latest.tar
docker load --input ./images/hyperledger-fabric-ca-latest.tar
docker load --input ./images/busybox-latest.tar
docker load --input ./images/hyperledger-fabric-peer-latest.tar
docker load --input ./images/hyperledger-fabric-orderer-latest.tar
docker load --input ./images/hyperledger-fabric-ccenv-latest.tar
docker load --input ./images/hyperledger-fabric-baseos-latest.tar
docker tag hyperledger/fabric-ca:latest hyperledger/fabric-ca:1.5
docker tag hyperledger/fabric-ca:latest hyperledger/fabric-ca:1.5.15
docker tag hyperledger/fabric-peer:latest hyperledger/fabric-peer:2.2
docker tag hyperledger/fabric-peer:latest hyperledger/fabric-peer:2.2.7
docker tag hyperledger/fabric-orderer:latest hyperledger/fabric-orderer:2.2
docker tag hyperledger/fabric-orderer:latest hyperledger/fabric-orderer:2.2.7
docker tag hyperledger/fabric-ccenv:latest hyperledger/fabric-ccenv:2.2
docker tag hyperledger/fabric-ccenv:latest hyperledger/fabric-ccenv:2.2.7
docker tag hyperledger/fabric-baseos:latest hyperledger/fabric-baseos:2.2
docker tag hyperledger/fabric-baseos:latest hyperledger/fabric-baseos:2.2.7

# start network, 
# this script will start the test-network, create channel, and deploy chaincode
echo -e "\e[1;33m正在启动网络 \e[0m"
# check fabric-samples
if [ ! -d "fabric-samples" ]; then
  echo "fabric-samples not found!"
  exit 1
fi
cd fabric-samples
# check ./start-network.sh
if [ ! -f "start-network.sh" ]; then
  echo "start-network.sh not found!"
  exit 1
fi
./start-network.sh
echo -e "\e[1;33m网络启动完成\e[0m"
